package uk.ac.bbk.dcs.pakdd2014;

import java.util.HashMap;

public class RepairDate {
	private int module;
	private int component;
	HashMap<Date,HashMap<Date,Integer>> repairs;
	
	public RepairDate(int module, int component) {
		this.module = module;
		this.component = component;
		repairs=new HashMap<Date,HashMap<Date,Integer>>();
	}
	public int getModule() {
		return module;
	}
	public int getComponent() {
		return component;
	}
	public HashMap<Date, HashMap<Date, Integer>> getRepaired() {
		return repairs;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + component;
		result = prime * result + module;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		RepairDate other = (RepairDate) obj;
		if (component != other.component)
			return false;
		if (module != other.module)
			return false;
		return true;
	}
	public void addRepair(int year1, int month1, int year2, int month2, int quantity) {
		Date date1=new Date(year1, month1);
		Date date2=new Date(year2, month2);
		if(repairs.containsKey(date1)){
			HashMap<Date,Integer> hm=repairs.get(date1);
			if(hm.containsKey(date2)){
				hm.put(date2, hm.get(date2) + quantity);
			} else{
				hm.put(date2, quantity);
			}
		} else{
			HashMap<Date,Integer> hm= new HashMap<Date,Integer>();
			hm.put(date2, quantity);
			repairs.put(date1, hm);
		}
		
	}
	@Override
	public String toString() {
		return "RepairDate [module=" + module + ", component=" + component
				+ ", repairs=" + repairs + "]";
	}
	
	
}
